<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="test1"></div>

<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>

<!-- jsx转为js -->
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

<script type="text/babel">
    // 字符串的ref，存在效率问题
    class Person extends React.Component {
        input2

        // React.createRef()调用后返回一个容器，该容器可以存储被ref所标识的节点
        // 该容器一个对象只能存一个
        myRef = React.createRef()

        showData1 = () => {
            console.log(this.myRef)
            console.log(this.myRef.current)
        }

        render() {
            return (
                   <div>
                       <input id="input1" ref={
                            this.myRef
                       } type="text" placeholder="点击按钮提示"/>

                       <button onClick={this.showData1}>点我提示数据</button>
                   </div>
            )
        }
    }

    ReactDOM.render(<Person name="tom1" age={18} sex="女"/>, document.getElementById("test1"))
</script>
</body>
</html>